home *** CD-ROM | disk | FTP | other *** search
- /*
- * SFskyedit - Star Fighter 3000 sky colours editor
- * Iconbar icon
- * Copyright (C) 2001 Chris Bazley
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public Licence as published by
- * the Free Software Foundation; either version 2 of the Licence, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public Licence for more details.
- *
- * You should have received a copy of the GNU General Public Licence
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- /* ANSI library files */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdbool.h>
-
- /* RISC OS library files */
- #include "wimp.h"
- #include "toolbox.h"
- #include "event.h"
- #include "wimplib.h"
- #include "iconbar.h"
- #include "flex.h"
-
- /* My library files */
- #include "err.h"
- #include "msgtrans.h"
- #include "Macros.h"
- #include "Loader.h"
- #include "SFformats.h" /* get Fednet filetype */
- #include "ViewsMenu.h"
- #include "NoBudge.h"
-
- /* Local headers */
- #include "EditSky.h"
- #include "SFSIconbar.h"
- #include "Utils.h"
-
- static ObjectId Iconbar_id;
-
- /* ----------------------------------------------------------------------- */
- /* Function prototypes */
-
- static ToolboxEventHandler _Iconbar_click;
-
- /* ----------------------------------------------------------------------- */
- /* Public functions */
-
- void Iconbar_initialise(ObjectId id)
- {
- Iconbar_id = id;
-
- /* Listen for ADJUST clicks */
- EF(event_register_toolbox_handler(id, Iconbar_Clicked, _Iconbar_click, NULL));
-
- /* Register listeners for files dropped on iconbar icon */
- EF(loader_register_listener(LISTENER_CLAIM, FILETYPE_SKYCOLS, id, NULL, load_compressed, Iconbar_openfile, NULL));
- }
-
- /* ----------------------------------------------------------------------- */
-
- void Iconbar_openfile(char *title, bool data_saved, flex_ptr buffer, int filetype, void *handle)
- {
- ObjectId editing_win;
-
- /* Check for existing windows */
- if(!data_saved || (editing_win = ViewsMenu_findview(title)) == NULL_ObjectId) {
-
- /* Check file format */
- if(!verify_sky_file((SF_SkyColours **)buffer)) {
- flex_free(buffer);
- return;
- }
-
- /* Create editing window */
- editing_win = EditSky_create((SF_SkyColours **)buffer, title, data_saved);
- if(editing_win == NULL_ObjectId) {
- flex_free(buffer);
- return;
- }
- }
- else
- flex_free(buffer); /* Already have an open editing window */
-
- /* Open editing window */
- RE(show_win_at_ptr(0, editing_win, Iconbar_id, NULL_ComponentId));
- }
-
- /* ----------------------------------------------------------------------- */
- /* Private functions */
-
- static int _Iconbar_click(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
- {
- ObjectId editing_win;
- SF_SkyColours *new_sky;
-
- if(FLAG_SET(((IconbarClickedEvent *)event)->hdr.flags, Iconbar_Clicked_Select)) {
- /* Initialise blank sky */
- if(!flex_alloc((flex_ptr)&new_sky, sizeof(SF_SkyColours)))
- MG_RETV("NoMem", 1); /* claim event */
-
- new_sky->min_sky_height = 0;
- new_sky->min_stars_height = 0;
- nobudge_register(256);
- memset(new_sky->shade, 0, 126*sizeof(unsigned int));
- nobudge_deregister();
-
- /* Open editing window */
- editing_win = EditSky_create((SF_SkyColours **)&new_sky, "<untitled>", 0);
- if(editing_win == NULL_ObjectId)
- flex_free((flex_ptr)&new_sky);
- else
- RE(toolbox_show_object(0, editing_win, Toolbox_ShowObject_Centre, NULL, id_block->self_id, NULL_ComponentId));
- return 1; /* claim event */
- }
-
- if(FLAG_SET(((IconbarClickedEvent *)event)->hdr.flags, Iconbar_Clicked_Adjust)) {
- /* bring all open windows to front */
- RE(ViewsMenu_showall());
- return 1; /* claim event */
- }
- return 0; /* not handled */
- }
-